//
// Created by Xu Xiao on 2022/9/9.
//
#include "Sln_K_Q2557.h"
#include "Sln_L_Q2558.h"

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <unordered_map>


#ifndef ALGORITHM_22_1_SOLUTION0909_H
#define ALGORITHM_22_1_SOLUTION0909_H

typedef long long ll;

using namespace std;

class Solution0909 {
public:
    static void G_Q2553() {
        //char dict[] = "FGHIJKLMNOPQRSTUVWXYZABCDE";
        char dict[] = "VWXYZABCDEFGHIJKLMNOPQRSTU";
        char cmd[105];
        while (gets_s(cmd)) {
            if (strcmp("ENDOFINPUT", cmd) == 0) break;
            if (strcmp("START", cmd) == 0) {
                string output;
                gets_s(cmd);
                for (int i = 0; i < strlen(cmd); i++) {
                    if (cmd[i] >= 'A' && cmd[i] <= 'Z')
                        output += dict[cmd[i] - 'A'];
                    else output += cmd[i];
                }
                cout << output << endl;
            }
        }
    }

    static void H_Q2554() {
        int n, k;
        int p1, p2;
        string s1, s2;
        while (cin >> n) {
            if (n == 0) break;
            cin >> k;
            vector<int> games(n + 1, 0);
            vector<int> wins(n + 1, 0);
            int times = k * n * (n - 1) / 2;
            for (int i = 0; i < times; i++) {
                cin >> p1 >> s1 >> p2 >> s2;
                int res = _game2554(p1, s1, p2, s2);
                if (res != 0) {
                    wins[res]++;
                    games[p1]++;
                    games[p2]++;
                }
            }
            for (int i = 1; i <= n; i++) {
                //cout << wins[i] << " " << games[i] << " ";
                if (games[i] == 0) {
                    printf("-\n");
                } else {
                    printf("%.3f\n", double(wins[i]) / games[i]);
                }
            }
            printf("\n");
        }
    }

    static int _game2554(int p1, string s1, int p2, string s2) {
        if (s1[0] == 'r') {
            if (s2[0] == 's') return p1;
            else if (s2[0] == 'p') return p2;
            else return 0;
        } else if (s1[0] == 's') {
            if (s2[0] == 'p') return p1;
            else if (s2[0] == 'r') return p2;
            else return 0;
        } else if (s1[0] == 'p') {
            if (s2[0] == 'r') return p1;
            else if (s2[0] == 's') return p2;
            else return 0;
        }
    }

    static void I_Q2555() {
        int t;
        cin >> t;
        while (t--) {
            int n, p;
            ll m;
            cin >> n >> m >> p;
            vector<ll> tid(p + 1), id(n + 1);
            for (int i = 1; i <= n; i++) {
                cin >> id[i];
            }
            ll ans = INFINITY, sum = 0;
            for (int i = 1; i <= p; i++) {
                ll a, b;
                cin >> a >> b;
                tid[i] = (id[a] - 1 - b + m) % m;
                sum += tid[i];
            }
            sort(tid.begin() + 1, tid.end());
            for (int i = 1; i <= p; i++) {
                ans = min(ans, sum + m * (i - 1) - tid[i] * p);
            }
            cout << ans << endl;
        }
    }

    static void J_Q2556() {
        //要求输出最上方的元素，注意方向的取法
        vector<vector<int>> d = {{0,  1},
                                 {1,  0},
                                 {1,  1},
                                 {-1, 1}};
        vector<vector<int>> board(19, vector<int>(19));
        int t;
        cin >> t;
        int i, j, k;
        while (t--) {
            for (i = 0; i < 19; i++)
                for (j = 0; j < 19; j++) {
                    cin >> board[i][j];
                }
            for (j = 0; j < 19; j++) {
                for (i = 0; i < 19; i++) {
                    if (board[i][j] == 0) continue;
                    for (k = 0; k < 4; k++) {
                        int x = i - d[k][0], y = j - d[k][1];
                        if (isValid(x, y) && board[x][y] == board[i][j]) continue;
                        int a;
                        for (a = 1; a <= 4; a++) {
                            x = i + d[k][0] * a;
                            y = j + d[k][1] * a;
                            if (board[x][y] != board[i][j] || !isValid(x, y)) break;
                        }
                        x = i + d[k][0] * 5;
                        y = j + d[k][1] * 5;
                        if (isValid(x, y) && board[x][y] == board[i][j]) continue;
                        if (!isValid(x, y)) continue;
                        if (a == 5) break;
                    }
                    if (k < 4) break;
                }
                if (i < 19) break;
            }
            if (j < 19) cout << board[i][j] << "\n" << i + 1 << " " << j + 1 << endl;
            else cout << 0 << endl;
        }
    }

    static bool isValid(int &x, int &y) {
        return x >= 0 && x < 19 && y >= 0 && y < 19;
    }

    static void K_Q2557() {
        int n;
        while (scanf("%d", &n), n) {
            auto *sln = new Sln_K_Q2557(n);
        }
    }

    static void L_Q2558() {
        new Sln_L_Q2558();
    }
};


#endif //ALGORITHM_22_1_SOLUTION0909_H
